<script setup>
import { ref } from "vue";
import { useUserStore } from "@/store/user";
import { getUserInfo } from "@/api/user";

const username = ref("");
const password = ref("");
const userStore = useUserStore();

const login = async () => {
  const res = await getUserInfo({
    username: username.value,
    password: password.value,
  });
  if (res?.token) {
    userStore.setValue("token", res.token); // 使用 setValue 设置 token
    userStore.setValue("user_info", "admin"); // 使用 setValue 设置 user_info
    const perms = await getUserPermissions();
    // 注意：这里可能需要根据实际情况使用 setValues 或 setValue 来设置 permissions
    // userStore.setValues({ permissions: perms });
    uni.redirectTo({ url: "/pages/index/index" });
  } else {
    uni.showToast({ title: "登录失败", icon: "none" });
  }
};
</script>
